﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;
using System.Data.SqlClient;

 

public partial class Frame_UserDetail : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            if (Request.QueryString["userid"] != null && !string.IsNullOrEmpty(Request.QueryString["userid"].ToString()))
            {
                this.hiduserid.Value = Request.QueryString["userid"].ToString();
                this.txtUserid.Enabled = false;
            }
            else
            {
                this.hiduserid.Value = "-1";
                this.txtUserid.Enabled = true;
            }
            hidPageIndex.Value = Request["PageIndex"] != null ? Request["PageIndex"].ToString() : "";
            this.InitPage();
        }
    }

    /// <summary>
    /// 初始化页面
    /// </summary>
    protected void InitPage()
    {
        //UserBL bl = new UserBL();
        //string strErrMessage = string.Empty;

        //if (this.hiduserid.Value != "-1")
        //{
        //    UserTable usertb = bl.GetUserInfo(this.hiduserid.Value);

        //    if (usertb != null)
        //    {
        //        this.txtUserid.Text = usertb.UserName;
        //        this.txtCusabbr.Text = usertb.RealName;
        //        this.txtChnname.Text = usertb.CHNNAME;
        //        this.txtEmail.Text = usertb.Email;

        //        if (usertb.IsActive.ToString() == "N")
        //            this.chkLock.Checked = true;
        //    }
        //}
    }

    /// <summary>
    /// 返回
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("User.aspx?PageIndex=" + this.hidPageIndex.Value);
    }

    /// <summary>
    /// 提交
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnInsert_Click(object sender, EventArgs e)
    {
        //if (!this.ValidData())
        //{
        //    return;
        //}

        //if (this.hiduserid.Value == "-1")
        //{
        //    UserBL bl = new UserBL();
        //    UserTable usertb = new UserTable();

        //    this.SetData(usertb);

        //    usertb.Password = "000000";
        //    usertb.USERLVL = "1";
        //    usertb.FLAG = "1";
        //    usertb.CORPLB = " ";
        //    usertb.YARD = "QD";
        //    usertb.YARDCN = "青岛";

        //    if (!bl.InsertUser(usertb))
        //    {
        //        lbErrorMessage.Text = "保存失败。";
        //    }
        //    else
        //    {
        //        lbErrorMessage.Text = "保存成功。";
        //        Response.Redirect("User.aspx?PageIndex=" + this.hidPageIndex.Value);
        //    }
        //}
        //else
        //{
        //    UserBL bl = new UserBL();
        //    UserTable usertb = bl.GetUserInfo(this.hiduserid.Value);

        //    this.SetData(usertb);

        //    if (!bl.UpdateUser(usertb))
        //    {
        //        lbErrorMessage.Text = "保存失败。";
        //    }
        //    else
        //    {
        //        lbErrorMessage.Text = "保存成功。";
        //        Response.Redirect("User.aspx?PageIndex=" + this.hidPageIndex.Value);
        //    }
        //}
    }

    ///// <summary>
    ///// 设置数据
    ///// </summary>
    ///// <param name="usertb"></param>
    //public void SetData(UserTable usertb)
    //{
    //    usertb.UserName = this.txtUserid.Text.ToUpper();
    //    usertb.CORPID = this.txtUserid.Text.ToUpper();
    //    usertb.RealName = this.txtCusabbr.Text;
    //    usertb.CHNNAME = this.txtChnname.Text;
    //    usertb.Email = this.txtEmail.Text;
    //    usertb.IsActive = char.Parse(this.chkLock.Checked ? "N" : "Y");
    //}

    /// <summary>
    /// 验证数据
    /// </summary>
    /// <returns></returns>
    protected bool ValidData()
    {
        bool boolRe = true;
        //StringBuilder strMessage = new StringBuilder();
        //UserBL _UserBl = new UserBL ();

        //if (string.IsNullOrEmpty(this.txtUserid.Text.Trim()))
        //{
        //    this.txtUserid.Focus();
        //    strMessage.Append("<font color='red'>用户名不能为空。</font></br>");
        //    boolRe = false;
        //}


        //if (string.IsNullOrEmpty(this.txtCusabbr.Text.Trim()))
        //{
        //    this.txtCusabbr.Focus();
        //    strMessage.Append("<font color='red'>用户简称不能为空。</font></br>");
        //    boolRe = false;
        //}

        //if (this.hiduserid.Value == "-1")
        //{
        //    UserBL bl = new UserBL();
        //    if (bl.GetUserInfo(this.txtUserid.Text.Trim()) != null)
        //    {
        //        this.txtUserid.Focus();
        //        strMessage.Append("<font color='red'>用户名已存在。</font></br>");
        //        boolRe = false;
        //    }
        //}

        //if (!string.IsNullOrEmpty(this.txtEmail.Text.Trim()))
        //{
        //    bool match = Regex.IsMatch(this.txtEmail.Text.Trim(), @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
        //    if (!match)
        //    {
        //        this.txtEmail.Focus();
        //        strMessage.Append("<font color='red'>请输入正确的邮箱格式。</font></br>");
        //        boolRe = false;
        //    }
        //}

        //lbErrorMessage.Text = strMessage.ToString();
        return boolRe;
    }
}